#include("/template/common/layout/_page_layout.html")
#@layout()

#define css()
<link rel="stylesheet" href="#(RESOURCE_HOST)/static/css/zTreeStyle/zTreeStyle.css" type="text/css">
<style>

</style>
#end

#define js()
<script type="text/javascript">
    var element = '#(fileProject.toJson())';
    var fileProject = JSON.parse(element);
    layui.use(['table', 'layer', 'upload','element'], function () {
        var table = layui.table
            , layer = layui.layer
            , $ = layui.jquery
            , element = layui.element
            , upload = layui.upload;

        //创建监听函数
         var xhrOnProgress=function(fun) {
            xhrOnProgress.onprogress = fun; //绑定监听
             //使用闭包实现监听绑
            return function() {
                //通过$.ajaxSettings.xhr();获得XMLHttpRequest对象
                var xhr = $.ajaxSettings.xhr();
                 //判断监听函数是否为函数
                  if (typeof xhrOnProgress.onprogress !== 'function')
                       return xhr;
                   //如果有监听函数并且xhr对象支持绑定时就把监听函数绑定上去
                    if (xhrOnProgress.onprogress && xhr.upload) {
                          xhr.upload.onprogress = xhrOnProgress.onprogress;
                    }
                    return xhr;
             }
         }
        upload.render({
            elem: '#add'
            , url: '#(ctxPath)/util/uploadFile'
            , accept: 'file'
            //,multiple: true
            , exts: 'pdf|png|jpeg|jpg'
            , data: {
                description: "文档文件"
            }
            ,xhr:xhrOnProgress
            ,progress:function(value){//上传进度回调 value进度值
                element.progress('upload-progress', value+'%')//设置页面进度条
            }
            , before: function (res) {
                <!--var bg = $('<div class="loading-bg"><i class="layui-icon layui-icon-loading layui-icon layui-anim layui-anim-rotate layui-anim-loop loading-ico"></i></div>');-->
                <!--$('body').prepend(bg);-->
                $('#upload-progress').removeClass('layui-hide');
            }, done: function (res) {
                <!--$('.loading-bg').remove();-->
                $('#upload-progress').addClass('layui-hide');
                if (res.code == 0) {
                    postFileID(fileProject.fileTypeID, res.data.fileId, fileProject.projectID);
                    return true;
                } else if (res.code == 1) {
                    layer.msg("文件上传失败，请重新选择上传！");
                    return false;
                }
            }
            , error: function (index, upload) {
                $('#upload-progress').addClass('layui-hide');
                layer.msg("文件上传错误！请重新尝试！");
            }
        });

    });

    function postFileID(_fileTypeID, _fileID, _projectID) {
        util.sendAjax({
            type: 'POST',
            url: '#(ctxPath)/app/project/finishUploadSave',
            data: {
                'fileProject.fileID': _fileID,
                'fileProject.projectID': _projectID,
                'fileProject.fileTypeID': _fileTypeID
            },
            loadFlag: true,
            success: function (data) {
                window.location.reload();
            },
            unSuccess: function (data) {
            }
        })
    }

    $("#sub").click(function () {
        util.sendAjax({
            type: 'POST',
            url: '#(ctxPath)/app/project/finishUploadSub',
            data: {
                fileProjectID: fileProject.id
            },
            loadFlag: true,
            success: function (data) {
                window.location.reload();
            },
            unSuccess: function (data) {
            }
        });
    });
    $("#view").click(function () {
        pop_show('查看文件', '#(ctxPath)/util/pdfView?fileID=' + fileProject.fileID, '', '', function () {
        });
    });
    $("#view2").click(function () {
        pop_show('查看文件', '#(ctxPath)/util/pdfView?fileID=' + fileProject.fileID, '', '', function () {
        });
    });

</script>
#end

#define content()
<div class="layui-fluid">
    <fieldset class="layui-elem-field site-demo-button" style="margin-top: 30px;">
        <legend class="x-center">终审报告</legend>
        #if(!fileProject.isEnable)
        <div class="x-center">
            <h3>上传终审报告文件</h3>
            <div class="layui-progress layui-hide" style="margin-bottom:10px" lay-showpercent="true" id="upload-progress" lay-filter="upload-progress" >
                <div class="layui-progress-bar layui-bg-green" lay-percent="0%"></div>
            </div>
            <button id="add" class="layui-btn layui-btn-small">上传</button>
        </div>
        #if(fileProject.fileID!=null)
        <div class="x-center">
            <h3>预览终审报告文件</h3>
            <button id="view" class="layui-btn layui-btn-small">预览</button>
        </div>
        <div class="x-center">
            <h3>提交终审报告文件</h3>
            <button id="sub" class="layui-btn layui-btn-small">提交</button>
        </div>
        #end
        #else
        <div class="x-center">
            <h1>你已提交文件</h1><button id="view2" class="layui-btn layui-btn-small" style="margin-top: 30px;">查看文件</button>
        </div>
        #end
    </fieldset>
</div>
#end